package com.qyhl.webtv.module_circle.circle.msg;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.google.android.material.tabs.TabLayout;
import com.gyf.immersionbar.ImmersionBar;
import com.qyhl.webtv.basiclib.base.BaseActivity;
import com.qyhl.webtv.basiclib.base.BaseIViewPresenter;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;
import com.qyhl.webtv.module_circle.R;
import com.qyhl.webtv.module_circle.R2;
import com.qyhl.webtv.module_circle.circle.msg.action.InteractionMessageFragment;
import com.qyhl.webtv.module_circle.circle.msg.chat.ChatMessageFragment;
import com.qyhl.webtv.module_circle.circle.msg.notice.NoticeMessageFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 圈子消息
 *
 * @author helin
 */
@Route(path = ARouterPathConstant.CIRCLE_MESSAGES)
public class CircleMessageActivity extends BaseActivity implements CircleMessageContract.CirclMessageView {

    /**
     * tab
     */
    @BindView(R2.id.circle_message_tab)
    TabLayout mCircleMessageTab;
    /**
     * viewPage
     */
    @BindView(R2.id.circle_message_view_page)
    ViewPager mCircleMessageViewPage;
    @BindView(R2.id.back)
    ImageView back;
    /***
     * 适配器
     */
    private SimpleFragmentPagerAdapter pagerAdapter;

    private List<Fragment> fragments = new ArrayList<>();
    private CircleMessagePresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getContentView() {
        return R.layout.circle_activity_circle_message;
    }

    @Override
    protected void setImmersionBar(ImmersionBar mImmersionBar) {
        setDefaultImmerBar();
    }

    @Override
    protected BaseIViewPresenter initBaseIViewPresenter() {
        return null;
    }

    @Override
    protected void init() {
        mPresenter = new CircleMessagePresenter(this);
        initView();
    }

    @Override
    protected void setListener() {

    }

    /**
     * 初始化控件
     */
    private void initView() {
        //添加tab选项
        pagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), this);
        mCircleMessageViewPage.setAdapter(pagerAdapter);
        mCircleMessageTab.setupWithViewPager(mCircleMessageViewPage);
        fragments.add(InteractionMessageFragment.newInstance());
        fragments.add(NoticeMessageFragment.newInstance());
        //自定义消息列表界面
        fragments.add(ChatMessageFragment.newInstance());
        //sdk消息列表界面
//        fragments.add(new LCIMConversationListFragment());
        mPresenter.systemMsgFlag();

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {

        private Context context;
        private final String[] mTitles = {"互动", "通知", "私信"};

        public SimpleFragmentPagerAdapter(FragmentManager fm, Context context) {
            super(fm);
            this.context = context;
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return mTitles.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }
    }


}
